package com.yy.permissions_general.module.system.dict.controller;

import com.yy.permissions_general.base.controller.BaseController;
import com.yy.permissions_general.common.aopSubmit.aop.NoRepeatSubmit;
import com.yy.permissions_general.module.system.aopLog.aop.MyLog;
import com.yy.permissions_general.module.system.dict.entity.DictData;
import com.yy.permissions_general.module.system.dict.service.DictDataService;
import com.yy.permissions_general.utils.ResultUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 字典详情前端控制器
 * </p>
 *
 * @author YY
 * @since 2021-08-08
 */
@RestController
@RequestMapping("/dictData")
//@RedisCache
public class DictDataController extends BaseController {


    @Resource
    private DictDataService dictDataService;

    /**
    * 查询列表
    * @param dictData
    * @param limit
    * @param page
    * @return
    */
    @RequestMapping("/list")
    @MyLog("查询字典详情")
    public ResultUtil list(DictData dictData,@RequestParam(value = "limit",defaultValue = "999999")int limit, @RequestParam(value = "page",defaultValue = "0")int page) {
      return ResultUtil.buildPagination(dictDataService.selectPageList(dictData,limit,page));
    }


    /**
     * 字典下拉
     * @param limit
     * @param page
     * @param map
     * @return
     */
    @RequestMapping("/getDictDataXMSelect")
    @MyLog("字典下拉")
    public ResultUtil getDictDataXMSelect(@RequestParam(value = "limit",defaultValue = "999999")int limit, @RequestParam(value = "page",defaultValue = "0")int page, @RequestParam Map<String,Object> map) {
        return ResultUtil.buildPagination(dictDataService.getDictDataXMSelect(map,limit,page));
    }

    /**
    * 新增数据
    * @param dictData
    * @return
    */
    @RequestMapping("/addDictData")
    @MyLog("添加字典详情")
    @PreAuthorize("hasPermission('/dictData/addDictData','dictData:addDictData')")
    public ResultUtil addDictData(DictData dictData) {
        dictDataService.addDictData(dictData);
        return ResultUtil.success();
    }

    /**
    * 修改数据
    * @param dictData
    * @return
    */
    @RequestMapping("/editDictData")
    @MyLog("修改字典详情")
    @PreAuthorize("hasPermission('/dictData/editDictData','dictData:editDictData')")
    public ResultUtil editDictData(DictData dictData) {
        dictDataService.editDictData(dictData);
        return ResultUtil.success();
    }

    /**
     * 修改状态
     * @param dictData
     * @return
     */
    @RequestMapping("/updateDictData")
    @MyLog("修改字典详情状态")
    @NoRepeatSubmit(key="dictData.updateDictData")
    @PreAuthorize("hasPermission('/dictData/updateDictData','dictData:updateDictData')")
    public ResultUtil updateDictData(DictData dictData) {
        dictDataService.updateDictData(dictData);
        return ResultUtil.success();
    }

    /**
    * 查看详情
    * @param id
    * @return
    */
    @RequestMapping("/detail")
    @MyLog("查询字典详情信息")
    public ResultUtil detail(Integer id) {
        DictData dictData = dictDataService.getDetailsById(id);
        return ResultUtil.success(dictData);
    }

    /**
    * 根据ID删除记录
    * @param id
    * @return
    */
    @RequestMapping("/delete")
    @MyLog("删除字典详情")
    @PreAuthorize("hasPermission('/dictData/delete','dictData:delete')")
    public ResultUtil delete(Integer id) {
        dictDataService.deleteById(id);
        return ResultUtil.success();
    }

    /**
    * 批量删除数据
    * @param ids ID集合
    * @return
    */
    @RequestMapping("/deleteBatch")
    @MyLog("批量删除字典详情")
    @PreAuthorize("hasPermission('/dictData/deleteBatch','dictData:deleteBatch')")
    public ResultUtil deleteBatch(@RequestParam(value = "ids[]",required = true) List<Long> ids) {
        dictDataService.deleteBatch(ids);
        return ResultUtil.success();
    }

}
